package com.zjwd.web.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zjwd.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zjwd.common.annotation.Log;
import com.zjwd.common.core.controller.BaseController;
import com.zjwd.common.core.domain.AjaxResult;
import com.zjwd.common.enums.BusinessType;
import com.zjwd.basic.domain.BasicReport;
import com.zjwd.basic.service.IBasicReportService;
import com.zjwd.common.utils.poi.ExcelUtils;
import com.zjwd.common.core.page.TableDataInfo;

/**
 * 基础通用报Controller
 *
 * @author liquan
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/basic/report")
public class BasicReportController extends BaseController {

    @Autowired
    private IBasicReportService service;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('basic:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicReport model) {
        startPage();
        List<BasicReport> list = service.selectModelList(model);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @PreAuthorize("@ss.hasPermi('basic:report:export')")
    @Log(title = "基础通用报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicReport model) {
        List<BasicReport> list = service.selectModelList(model);
        ExcelUtils<BasicReport> util = new ExcelUtils<BasicReport>(BasicReport.class);
        util.exportExcel(response, list, "基础通用报数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(service.getModelById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('basic:report:add')")
    @Log(title = "基础通用报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicReport model) {
        return toAjax(service.insert(model));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('basic:report:edit')")
    @Log(title = "基础通用报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicReport model) {
        return toAjax(service.update(model));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('basic:report:remove')")
    @Log(title = "基础通用报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[]ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
